package playn.game.menu.states;

import playn.core.GroupLayer;
import playn.game.core.Button;
import playn.game.core.Game;
import playn.game.core.State;
import playn.game.menu.Menu;

public class Levels extends State {

	private final static String LEVEL_TAG="Level"; 
	public final static String LEVELS_BUTTON_ID="Levels"; 
	public final static String BACK_BUTTON_ID="Back"; 
	
	
	public Levels(GroupLayer layer){
		super(layer);
		name="LEVELS";
		map=Game.maps.get("Levels.tmx");
		map.getLayer("Background").setPriority(-3);
		map.getLayer("Levels").setPriority(-2);
		map.getLayer("Figures").setPriority(-1);
	}
	
	@Override
	public void start(){
		super.start();
		transition.addIn(Game.background.layer);
	}

	@Override
	public void onPress(Button button){
		String id=button.id();
		
		if(id.contains(LEVEL_TAG)){
			id=id.replaceAll(LEVEL_TAG, "");

			int levelNumber=Integer.parseInt(id);
			
			transition.addOut(Game.background.layer);
			
			Game.level.start(levelNumber);
			Game.menu.switchTo(Menu.ACTION);
			
		} else if (button.id().equalsIgnoreCase(Levels.BACK_BUTTON_ID)) {
			Game.menu.switchTo(Menu.START);
		} else {
			super.onPress(button);
		}
	}

	
	
}
